#include <stdio.h>

/*
 * 除法优化之无符号非2的幂优化
 */

int main(int argc, char* argv[])
{
	unsigned int NumberOne = 0;
	unsigned int NumberTwo = 0;

	scanf("%u",&NumberOne);
	scanf("%u",&NumberTwo);

	unsigned int Count1 = NumberOne / 3;

	unsigned int Count2 = NumberTwo / 5;

	unsigned int Count3 = NumberTwo / 6;

	unsigned int Count4 = NumberTwo / 9;

	printf("%d %d %d %d", Count4, Count3, Count2, Count1);

	return 0;
}

#if 0

	.text:00401005 mov [esp+8+var_8], eax
	.text:00401009 mov [esp+8+var_4], eax

	.text:0040102B mov eax, 2863311531	// 0xaaaaaaab
	.text:00401030 mov ecx, [esp+18h+var_4]
	.text:00401034 mul [esp+18h+var_8]
	.text:00401038 shr edx, 1		// 2^(32+1) / 2863311531 = 2.9999999 = 3

	.text:0040103A mov eax, 3435973837	// 0xcccccccd
	.text:0040103F push edx
	.text:00401040 mul ecx
	.text:00401042 shr edx, 2		// 2^(32+2) / 3435973837 = 4.9999999 = 5

	.text:00401045 mov eax, 0AAAAAAABh
	.text:0040104A push edx
	.text:0040104B mul ecx
	.text:0040104D shr edx, 2		// 2^(32+2) / 2863311531 = 5.9999999 = 6

	.text:00401050 mov eax, 38E38E39h	// 954437177
	.text:00401055 push edx
	.text:00401056 mul ecx
	.text:00401058 shr edx, 1		// 2^(32+1) / 954437177 = 8.9999999 = 9
	.text:0040105A push edx

/*
 * 无符号非2的幂除数为正代码反汇编还原
 */

	看如上代码，根据除法转为乘法公式 (a * b) >> n，我们可以求出：

	2^n / b = M ==> 2^n/M = b (除数常量)

	这里只不过是换成了无符号而已。

	还原公式还是同上

	.text:0040102B mov eax, 2863311531			// 0xAAAAAAAB
	.text:00401030 mov ecx, [esp+18h+var_4]
	.text:00401034 mul [esp+18h+var_8]
	.text:00401038 shr edx, 1

	取 N 值 = 1，取M值 = 2863311531

	操作的是edx，所以：

	被除数 = 2^33     除数 = M     求除数公式 = 2^n/M = b

	代入公式
	
	2^33 / 2863311531 = 2.999999999 向上取整 = 3 所以得出这里的除数为3. 
	
	ecx = var4所以这里反汇编为高级代码为 var_4 / 3




#endif
